package org.javaboy.consumer01.consumer;

import org.javaboy.consumer01.config.QueueConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

//@Component
public class SimpleConsumer {

    private static final Logger logger = LoggerFactory.getLogger(SimpleConsumer.class);

    /**
     * 通过 注解 @RabbitListener 监听队列
     * <p>
     * concurrency 并发数，默认是 1，可以设置多个消费者同时消费消息
     * 相当于同时开启了 10 个子线程去消费消息
     */
    @RabbitListener(queues = QueueConfig.QUEUE_NAME, concurrency = "10")
    public void handleMsg(String msg) {
        logger.info("ThreadName:{} handleMsg 接收到消息：{}", Thread.currentThread().getName(), msg);
    }

    /**
     * 两个消费者监听同一个队列
     *
     * @param msg
     */
    @RabbitListener(queues = QueueConfig.QUEUE_NAME)
    public void handleMsg2(String msg) {
        logger.info("handleMsg2 接收到消息：{}", msg);
    }
}
